﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace l1cs.server.model
{
    public class L1TaxCalculator
    {
        /// <summary>戦争税は15%固定</summary>
        private const int WAR_TAX_RATES = 15;

        /// <summary>国税は10%固定（地域税に対する割合）</summary>
        private const int NATIONAL_TAX_RATES = 10;

        /// <summary>ディアド税は10%固定（戦争税に対する割合）</summary>
        private const int DIAD_TAX_RATES = 10;

        private int _taxRatesCastle;
        private int _taxRatesTown;
        private int _taxRatesWar = WAR_TAX_RATES;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="merchantNpcId">計算対象商店のNPCID</param>
        public L1TaxCalculator( int merchantNpcId )
        {
            _taxRatesCastle = L1CastleLocation.getCastleTaxRateByNpcId( merchantNpcId );
            _taxRatesTown = L1TownLocation.getTownTaxRateByNpcid( merchantNpcId );
        }

        public int calcTotalTaxPrice( int price )
        {
            int taxCastle = price * _taxRatesCastle;
            int taxTown = price * _taxRatesTown;
            int taxWar = price * WAR_TAX_RATES;
            return ( taxCastle + taxTown + taxWar ) / 100;
        }

        /// <summary>
        /// 個別に計算する為、丸め誤差が出る。
        /// </summary>
        /// <param name="price"></param>
        /// <returns></returns>
        public int calcCastleTaxPrice( int price )
        {
            return ( price * _taxRatesCastle ) / 100 - calcNationalTaxPrice( price );
        }

        public int calcNationalTaxPrice( int price )
        {
            return ( price * _taxRatesCastle ) / 100 / ( 100 / NATIONAL_TAX_RATES );
        }

        public int calcTownTaxPrice( int price )
        {
            return ( price * _taxRatesTown ) / 100;
        }

        public int calcWarTaxPrice( int price )
        {
            return ( price * _taxRatesWar ) / 100;
        }

        public int calcDiadTaxPrice( int price )
        {
            return ( price * _taxRatesWar ) / 100 / ( 100 / DIAD_TAX_RATES );
        }

        /// <summary>
        /// 課税後の価格を求める。
        /// </summary>
        /// <param name="price">課税前の価格</param>
        /// <returns>課税後の価格</returns>
        public int layTax( int price )
        {
            return price + calcTotalTaxPrice( price );
        }
    }
}
